package handler

import (
	"encoding/base64"
	"git.oschina.net/fanbuchi/scf-server/diskv"
	"github.com/gin-gonic/gin"
)

type DiskVHandler struct {

}


// @Summary 内存数据库写入/tmp
// @Description 内存数据库写入/tmp
// @Tags diskv
// @Accept  json
// @Produce  json
// @Param   value  query    string     true        "默认value" default(chengdukm@gmail.com)
// @Success 200 {object} domain.Rsp    "调用成功"
// @Router /diskv/create [post]
func ( handler*DiskVHandler)Create(c *gin.Context){
	key:="users/blacklist"
	value:=c.Query("value")
	d:=diskv.GetDiskv()
	v:=[]byte(value)
	path:=base64.StdEncoding.EncodeToString(v)
	err:=d.WriteString(key+"/"+path,value)
	HandlerResponse(c,nil,err)
}


// @Summary 内存数据库读取/tmp
// @Description 内存数据库读取/tmp
// @Tags diskv
// @Accept  json
// @Produce  json
// @Param   value    query    string     true        "默认value" default(chengdukm@gmail.com)
// @Success 200 {object} domain.Rsp    "调用成功"
// @Router /diskv/query [get]
func ( handler*DiskVHandler)Query(c *gin.Context){
	key:="users/blacklist"
	value:=c.Query("value")
	v:=[]byte(value)
	disk:=diskv.GetDiskv()
	path:=base64.StdEncoding.EncodeToString(v)
	data:=disk.ReadString(key+"/"+path)
	HandlerResponse(c,data,nil)
}
